﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Citi.RoutineBase;
using Citi.TasksAutomation.Domain.Sharepoint.OTFPC;
using Citi.Helpers;
using System.Globalization;
using System.Configuration;
using Citi.TasksAutomation.Domain;
using OfficeOpenXml;
using System.IO;
using Citi.SecurityHelper;

namespace Citi.TasksAutomation.SchedulerUI
{
    public class MondayTasks : IExecutableRoutine
    {
        public const string PathFolder = @"\\LACBRA001FS0010\DATA_GRP1\FINTOOLS\Config\Controls\TasksAutomation\";

        public void Rollback(ref ICurrentAction currentAction)
        {

        }

        public void Start(DateTime scheduledDate, ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            var robotUsername = parameters["RobotUsername"].ToString();
            var robotPassword = parameters["RobotPassword"].ToString();
            var soeidResponsible = parameters["SoeidResponsible"].ToString();

            using (ImpersonateCitiUser.GetImpersonateUser(soeidResponsible, robotUsername, robotPassword))
            {
                currentAction.Description = "Getting Tasks in Sharepoint";
                var tasks = new Task().GetAllTasks().Where(x => x.TargetDate.HasValue && x.TargetDate.Value.WeekOfYear() == scheduledDate.WeekOfYear()
                            && x.TargetDate.Value.Year == scheduledDate.Year);

                var task = new Domain.Task();

                task.SendUserNotification(tasks, ref currentAction);
                task.SendEmails();
            }
        }

        public void Stop(ref ICurrentAction currentAction)
        {

        }
    }
}
